<?php

class Chat {

    public static function getChatData($room, $data) {
        $db = DBUtils::Create();
        $id = $room->getId();
        $lines_arr = $db->getChatLines($id);
        $i = 0;
        $res = array();

        $lines_data = array();
        foreach ($lines_arr as $line_arr) {
            $l = array();
            $l['id'] = $line_arr['id'];
            
            $l['line'] = $line_arr['line'];
            $l['name'] = $line_arr['name'];
            $lines_data[$i] = $l;
            $i += 1;
        }
        $res['lines'] = $lines_data;
        $res['placeholder'] = "insert text here...";
        $data['chat'] = $res;
        return $data;
    }
    
    public static function getChatIDs($room) {
        $db = DBUtils::Create();
        $id = $room->getId();
        $lines_arr = $db->getChatLinesIDs($id);
        $lines_data = array();
        foreach ($lines_arr as $line_arr) {
            array_push($lines_data, $line_arr['id']);
        }
        return $lines_data;
    }

    public static function addLine($room, $userid, $line) {
        $db = DBUtils::Create();
        $id = $room->getId();
        $db->setChatLine($id, $userid, $line);
    }

}

?>